const App= getApp()
Page({
    data:{
        hidden:false,
        address:[],
    },
    onLoad(){
        this.getUseraddResslist()
    },
    onShow(){
        this.getUseraddResslist()
    },
    addRessAction:function(){
        wx.navigateTo({
          url: '../add/index',
        })
    },
    getUseraddResslist:function(){
        var user_id=wx.getStorageSync('user_id')
        var that=this
        wx.showToast({
            title: '加载中',
            icon: 'loading',
            duration: 20000
            })
        App.HttpService.getUserResslist({
            user_id:user_id
        }).then(data=>{
            if(data.meat.code==0){
                 wx.hideToast()
                that.setData({
                    address:data.data
                })
            }
        })
    },
    radioChange:function(e){
        var id=e.detail.value
        var user_id=wx.getStorageSync('user_id')
        var that=this
        App.HttpService.editUserRessCode({
            id:id,
            user_id:user_id
        }).then(data=>{
            if(data.meat.code==0){
                that.setData({
                    address:data.data
                })
            }
        })
    },
    editRessAction:function(e){
        var id=e.currentTarget.dataset.id
        wx.navigateTo({
          url: '../edit/index?id='+id,
        })
    },
    //删除地址
    delete_RessAction:function(e){
        var id=e.currentTarget.dataset.id
        var that=this
        wx.showModal({
            title: '温馨提示',
            content: '您确定需要删除该地址吗?',
            success: function(res) {
                if (res.confirm) {
                    wx.showToast({
                        title: '删除中..',
                        icon: 'loading',
                        duration: 10000
                        })
                App.HttpService.deletUserAddRessInfo({
                    id:id
                }).then(data=>{
                    if(data.meat.code==0){
                        setTimeout(function(){
                            wx.hideToast()
                            that.getUseraddResslist()
                            },2000)
                    }
                })
                    
                }
            }
            })
    }
})